package com.lzy.system.organization.controller;

import com.lzy.conf.JSONResult;
import com.lzy.system.organization.dto.SysResDTO;
import com.lzy.system.organization.entity.SysRes;
import com.lzy.system.organization.service.ISysResService;
import com.lzy.utils.ValidList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 资源 前端控制器
 * </p>
 *
 * @author lcc
 * @since 2022-08-17
 */
@RestController
@RequestMapping("/organization/sysRes")
@Api(tags = "资源")
@Slf4j
public class SysResController {
    private ISysResService iSysResService;

    @Autowired
    public SysResController(ISysResService iSysResService) {
        this.iSysResService = iSysResService;
    }

    @ApiOperation("根据id查询资源")
    @RequestMapping(value = "/getById/{id}", method = RequestMethod.GET)
    public JSONResult getById(@ApiParam("资源id") @PathVariable(value = "id",required = true) long id) throws Exception {
        return JSONResult.ok(iSysResService.getById(id));
    }
    @ApiOperation("查询资源列表")
    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public JSONResult getList() throws Exception {
        return JSONResult.ok(iSysResService.getList());
    }

    @ApiOperation("查询资源目录列表")
    @RequestMapping(value = "getListDir", method = RequestMethod.POST)
    public JSONResult getListDir() throws Exception {
        return JSONResult.ok(iSysResService.getListDir());
    }

    @ApiOperation("添加资源")
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public JSONResult save(@ApiParam("资源信息") @RequestBody @Validated() SysResDTO sysResDTO) throws Exception {
        return JSONResult.ok(iSysResService.add(sysResDTO));
    }

    @ApiOperation("修改资源")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public JSONResult update(@ApiParam("资源信息") @RequestBody @Validated() SysResDTO sysResDTO) throws Exception {
        return JSONResult.ok(iSysResService.update(sysResDTO));
    }

    @ApiOperation("删除资源")
    @RequestMapping(value = "delById/{id}", method = RequestMethod.DELETE)
    public JSONResult delById(@ApiParam("资源id") @PathVariable(value = "id",required = true) long id) throws Exception {
        return JSONResult.ok(iSysResService.delById(id));
    }

    @ApiOperation("批量删除资源")
    @RequestMapping(value = "delBatch", method = RequestMethod.DELETE)
    public JSONResult del(
            @ApiParam("资源列表") @RequestBody @Validated() ValidList<SysRes> sysRes
    ) throws Exception {
        return JSONResult.ok(iSysResService.delBatch(sysRes));
    }

}
